package com.common.user.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import com.common.user.domain.User;
import com.common.user.service.UserService;

@Component
public class OAuth2UserDetailsService implements UserDetailsService {
	
	@Autowired 
	private UserService userSercvice;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		
		User user = userSercvice.findByUsername(username);
		
		if(user == null) {
			throw new UsernameNotFoundException("用户：" + username + "不存在");
		}

		return user;
	}

}
